<template>
  <div class="app-container">
    <el-form :inline="true" :model="listQuery" @submit.native.prevent>
      <el-form-item label="品牌名称">
        <el-input v-model="listQuery.q_name"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="small" @click="this.getList">查询</el-button>
        <el-button icon="el-icon-refresh-left" size="small" @click="reset">重置</el-button>
      </el-form-item>
    </el-form>
    <div class="button-table-margin">
      <el-button size="small" type="primary" @click="passBtn" v-permission="['admin/product/brand/auditing']">审核通过</el-button>
      <el-button size="small" type="primary" @click="rejectBtn" v-permission="['admin/product/brand/auditing']">审核驳回</el-button>
    </div>
    <el-table
      ref="singleTable"
      :data="dataList"
      v-loading="listLoading"
      border
      fit
      highlight-current-row
      style="width: 100%"
      @current-change="handleCurrentChange"
    >
      <el-table-column
        type="index"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column
        label="图片地址"
      >
        <template slot-scope="scope">
          <img width="102" height="36" :src="$imagePath+scope.row.image" alt="">
        </template>
      </el-table-column>
      <el-table-column
        property="name"
        label="品牌名称">
      </el-table-column>
      <el-table-column
        property="nameFirst"
        label="首字母">
      </el-table-column>
      <el-table-column
        label="状态"
      >
        <template slot-scope="scope">
          {{ codeBox.SELLER_STATE[scope.row.state] }}
        </template>
      </el-table-column>
      <el-table-column
        property="sellerName"
        label="申请商家">
      </el-table-column>
      <el-table-column
        width="160"
        property="updateTime"
        label="修改时间">
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
  </div>
</template>
<script>
import { todoList, passCateReview } from '@/api/product'
import { getCodeManager } from '@/api/all'
import Pagination from '@/components/Pagination'
import { Message } from 'element-ui'
export default {
  name: 'Brand',
  components: { Pagination },
  data() {
    return {
      dataList: [],
      checkBrandName: '',
      total: 0,
      listLoading: false,
      listQuery: {
        page: 1,
        limit: 20,
        q_name: ''
      },
      currentRow: null
    }
  },
  created() {
    getCodeManager('SELLER_STATE', () => {})
    this.getList()
  },
  methods: {
    handleCurrentChange(val) {
      // 选中当前行数据
      this.currentRow = val
    },
    // 获取列表数据
    getList() {
      this.listLoading = true
      todoList(this.listQuery).then(response => {
        this.dataList = response.data.rows
        this.total = response.data.total
        this.listLoading = false
        console.log(this.dataList)
      })
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    reset() {
      this.listQuery.q_name = ''
      this.getList()
    },
    passBtn() {
      if(!this.currentRow) {
        Message.error('请选择操作行。')
        return;
      };
      if(this.currentRow.state != 1) {
        Message.error('只有[提交审核]的记录可以审核')
        return;
      };
      this.$confirm('确定要审核通过吗，审核通过品牌进入品牌库？', '提示', {
        onfirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        passCateReview({status: 2, id: this.currentRow.id}).then(res => {
          if(res.data.success) {
            this.$message({
              type: 'success',
              message: '操作成功'
            });
            this.getList()
          } else {
            this.$message({
              type: 'error',
              message: res.data.message
            });
          }
        })
      })
    },
    rejectBtn() {
      if(!this.currentRow) {
        Message.error('请选择操作行。')
        return;
      };
      if(this.currentRow.state != 1) {
        Message.error('只有[提交审核]的记录可以审核')
        return;
      };
      this.$confirm('确定要驳回商家申请？', '提示', {
        onfirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        passCateReview({status: 3, id: this.currentRow.id}).then(res => {
          if(res.data.success) {
            this.$message({
              type: 'success',
              message: '操作成功'
            });
            this.getList()
          } else {
            this.$message({
              type: 'error',
              message: res.data.message
            });
          }
        })
      })
    }
  }
}
</script>
<style scoped>
  .filter-container .el-col-6 {
    margin-bottom: 15px;
  }
  .filter-item {
    margin-bottom: 0
  }
  /deep/ .filter-container label {
    font-size: 14px;
    font-weight: 500;
    margin-right: 10px;
  }
</style>
